/*
 * @Description: 组件引用
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-04-11 23:15:04
 * @LastEditTime: 2021-04-11 23:25:06
 */
import { ref, onBeforeUpdate, Ref } from 'vue'

export function useRefs(): [
	Ref<HTMLElement[]>,
	(index: number) => (el: HTMLElement) => void
] {
	const refs = ref<HTMLElement[]>([])

	onBeforeUpdate(() => {
		refs.value = []
	})

	const setRefs = (index: number) => (el: HTMLElement) => {
		refs.value[index] = el
	}

	return [refs, setRefs]
}
